#--------------------------------------------------------------------
#   meshemitter.tcl
#   ===============
#   Demonstrates nmeshemitter class, which emits particles from
#   a mesh (a static mesh in this case for simplicity).
#
#   01-Nov-00   floh    created
#--------------------------------------------------------------------
def posipol():
	posz=new ('nipol','posz')
	sel ('posz')
	posz.connect('tz')
	posz.addkey1f(0,0)
	posz.addkey1f(1,-20)
	posz.addkey1f(2,-20)
	posz.addkey1f(3,0)
	sel ('..')
	posy=new ('nipol','posy')
	sel ('posy')
	posy.connect('ty')
	posy.addkey1f(0,0)
	posy.addkey1f(0.2,1)
	posy.addkey1f(0.4,-1)
	posy.addkey1f(0.6,1)
	posy.addkey1f(0.8,0)
	sel ('..')
	posx=new ('nipol','posx')
	sel ('posx')
	posx.connect('tx')
	posx.addkey1f(0,0)
	posx.addkey1f(1,-20)
	posx.addkey1f(2,20)
	posx.addkey1f(3,0)
	sel ('..')
	ip=new ('nipol','ip')
	sel ('ip')
	#ip.setactive(1)
	ip.connect('rxyz')
	ip.addkey3f(0,0,0,0)
	ip.addkey3f(10,360,1080,720)
	sel ('..')
sel ('/usr/scene')
execfile ('licht.py')
# this is the actual donut
donut_pos=new ('n3dnode','donut_pos')
sel ('donut_pos')
donut_pos.sxyz(0.5,0.5,0.5)
posipol ()
donut=new ('nmeshnode','donut')
sel ('donut')
donut.setfilename("../meshes/torus1.n3d")
sel ('..')
shader=new ('nshadernode','shader')
sel ('shader')
shader.setnumstages(1)
shader.setcolorop(0,"mul tex prev" )
shader.begintunit(0)
shader.setaddress('wrap','wrap')
shader.setminmagfilter('linear','linear')
shader.settexcoordsrc('uv0')
shader.setenabletransform(0)
shader.endtunit()
shader.setlightenable(1)
shader.setdiffuse(1,1,1,1)
shader.setemissive(0,0,0,0)
shader.setambient(1,1,1,1)
shader.setalphaenable(0)
sel ('..')
tex=new ('ntexarraynode','tex')
sel ('tex')
tex.settexture(0,'../bmp/lava.bmp','none')
sel ('..')
sel ('..')
psystem_pos=new ('n3dnode','psystem_pos')
sel ('psystem_pos')
psystem_pos.sxyz(0.5,0.5,0.5)
posipol ()
# define the shader for the particle system, the particle
# renderer generates vertex colors, thus we turn off lighting,
sn=new ('nshadernode','sn')
sel ('sn')
sn.setnumstages(1)
sn.setcolorop(0,"mul tex prev" )
sn.begintunit(0)
sn.setaddress('wrap','wrap')
sn.setminmagfilter('linear','linear')
sn.settexcoordsrc('uv0')
sn.setenabletransform(0)
sn.endtunit()
sn.setlightenable(0)
sn.setalphaenable(1)
sn.setzwriteenable(0)
sn.setalphablend('one','one')
sel ('..')
tex0=new ('ntexarraynode','tex0')
sel ('tex0')
tex0.settexture(0,'../bmp/glow.bmp','none')
sel ('..')
# define the particle system hierarchie, consisting of a
# nspriterender object at the top, and a nmeshemitter and
# nmeshnode below it
# the particle renderer (renders particles as viewer aligned sprites...)
sr=new ('nspriterender','sr')
sel ('sr')
# the particle emitter (emits particles from vertices of a vbuffer)
pemit=new ('nmeshemitter','pemit')
sel ('pemit')
# here's the mesh which contains the vertices
# that should be used as initial particle positions
# note that it is set to 'readonly' and 'setactive false'
# because it may not render itself (it only serves as
# the source for the particle emitter
mesh=new ('nmeshnode','mesh')
sel ('mesh')
#mesh.setactive(0)
mesh.setreadonly(1)
mesh.setfilename("../meshes/torus1.n3d")
sel ('..')
# particle emitter attributes...
pemit.setreptype('oneshot')
pemit.settimes(0,0,0)
pemit.setlifetime(1.2)
pemit.setfreq(800)
pemit.setspeed(0)
pemit.setaccel(0,0,0)
pemit.setmeshnode('mesh')
sel ('..')
# particle renderer attributes...
sr.setemitter('pemit')
sr.setspin(0)
sr.setspinaccel(0)
sr.beginkeys(6)
sr.setkey(0,1.2,0.1,1.0,0.0,0.2,1.0)
sr.setkey(1,1.0,0.2,1.0,0.2,0.2,1.0)
sr.setkey(2,0.4,0.3,1.0,0.6,0.2,1.0)
sr.setkey(3,0.3,0.4,0.5,0.0,0.7,1.0)
sr.setkey(4,0.2,0.5,0.2,0.5,1.0,1.0)
sr.setkey(5,0.01,0.6,0.0,0.0,0.0,1.0)
sr.endkeys()
sel ('..')
sel ('..')
